func resourceTrafficIPGroupRead(d *schema.ResourceData, meta interface{}) error { c := meta.(*providerConfig).client r, resp, err := c.GetTrafficIPGroup(d.Get("name").(string)) if err != nil { if resp != nil && resp.StatusCode == 404 { // The resource doesn't exist anymore d.SetId("") return nil } return fmt.Errorf("Error reading resource: %s", err) } d.Set("enabled", bool(*r.Basic.Enabled)) d.Set("hash_source_port", bool(*r.Basic.HashSourcePort)) d.Set("ipaddresses", []string(*r.Basic.IPAddresses)) d.Set("keeptogether", bool(*r.Basic.KeepTogether)) d.Set("location", int(*r.Basic.Location)) d.Set("machines", []string(*r.Basic.Machines)) d.Set("mode", string(*r.Basic.Mode)) d.Set("multicast", string(*r.Basic.Multicast)) d.Set("note", string(*r.Basic.Note)) d.Set("rhi_ospfv2_metric_base", int(*r.Basic.RHIOSPFV2MetricBase)) d.Set("rhi_ospfv2_passive_metric_offset", int(*r.Basic.RHIOSPFV2PassiveMetricOffset)) d.Set("slaves", []string(*r.Basic.Slaves)) return nil }
func resourceVirtualServerSet(d *schema.ResourceData, meta interface{}) error { c := meta.(*providerConfig).client r := stingray.NewVirtualServer(d.Get("name").(string)) setString(&r.ConnectionErrors.ErrorFile, d, "connection_errors_error_file") setInt(&r.Connection.KeepaliveTimeout, d, "connection_keepalive_timeout") setInt(&r.Connection.Timeout, d, "connection_timeout") setInt(&r.Basic.ConnectTimeout, d, "connect_timeout") setBool(&r.Basic.Enabled, d, "enabled") // NOTE: Set default for gzip_include_mime // // Default does not work for sets (only for primitive types), // so we must use GetOK. This means we will get the default // value if the parameter is unset OR set to the empty value. if _, ok := d.GetOk("gzip_include_mime"); ok { setStringSet(&r.Gzip.IncludeMIME, d, "gzip_include_mime") } else { r.Gzip.IncludeMIME = &[]string{"text/html", "text/plain"} } setBool(&r.Gzip.Enabled, d, "gzip_enabled") setString(&r.HTTP.LocationRewrite, d, "http_location_rewrite") setBool(&r.Basic.ListenOnAny, d, "listen_on_any") setStringSet(&r.Basic.ListenOnTrafficIPs, d, "listen_on_traffic_ips") setBool(&r.Log.Enabled, d, "log_enabled") setString(&r.Log.Filename, d, "log_filename") setString(&r.Log.Format, d, "log_format") setBool(&r.Log.ServerConnectionFailures, d, "log_server_connection_failures") setString(&r.Basic.Note, d, "note") setString(&r.Basic.Pool, d, "pool") setInt(&r.Basic.Port, d, "port") setString(&r.Basic.Protocol, d, "protocol") setBool(&r.RecentConnections.SaveAll, d, "recent_connections_save_all") setStringList(&r.Basic.RequestRules, d, "request_rules") setStringList(&r.Basic.ResponseRules, d, "response_rules") setBool(&r.SSL.AddHTTPHeaders, d, "ssl_add_http_headers") setBool(&r.Basic.SSLDecrypt, d, "ssl_decrypt") setString(&r.SSL.ServerCertDefault, d, "ssl_server_cert_default") setServerCertHostMappingTable(&r.SSL.ServerCertHostMapping, d, "ssl_server_cert_host_mapping") setString(&r.Syslog.Format, d, "syslog_format") setBool(&r.WebCache.Enabled, d, "web_cache_enabled") setInt(&r.WebCache.MaxTime, d, "web_cache_max_time") _, err := c.Set(r) if err != nil { return err } d.SetId(d.Get("name").(string)) return nil }
func resourceMonitorScriptSet(d *schema.ResourceData, meta interface{}) error { c := meta.(*providerConfig).client r := stingray.NewMonitorScript(d.Get("name").(string)) r.Content = []byte(d.Get("content").(string)) _, err := c.Set(r) if err != nil { return err } d.SetId(d.Get("name").(string)) return nil }
func resourceVirtualServerRead(d *schema.ResourceData, meta interface{}) error { c := meta.(*providerConfig).client r, resp, err := c.GetVirtualServer(d.Get("name").(string)) if err != nil { if resp != nil && resp.StatusCode == 404 { // The resource doesn't exist anymore d.SetId("") return nil } return fmt.Errorf("Error reading resource: %s", err) } d.Set("connection_errors_error_file", string(*r.ConnectionErrors.ErrorFile)) d.Set("connection_keepalive_timeout", int(*r.Connection.KeepaliveTimeout)) d.Set("connection_timeout", int(*r.Connection.Timeout)) d.Set("connect_timeout", int(*r.Basic.ConnectTimeout)) d.Set("enabled", bool(*r.Basic.Enabled)) d.Set("gzip_enabled", bool(*r.Gzip.Enabled)) d.Set("gzip_include_mime", []string(*r.Gzip.IncludeMIME)) d.Set("http_location_rewrite", string(*r.HTTP.LocationRewrite)) d.Set("listen_on_any", bool(*r.Basic.ListenOnAny)) d.Set("listen_on_traffic_ips", []string(*r.Basic.ListenOnTrafficIPs)) d.Set("log_enabled", bool(*r.Log.Enabled)) d.Set("log_filename", string(*r.Log.Filename)) d.Set("log_format", string(*r.Log.Format)) d.Set("log_server_connection_failures", bool(*r.Log.ServerConnectionFailures)) d.Set("note", string(*r.Basic.Note)) d.Set("pool", string(*r.Basic.Pool)) d.Set("port", int(*r.Basic.Port)) d.Set("protocol", string(*r.Basic.Protocol)) d.Set("recent_connections_save_all", bool(*r.RecentConnections.SaveAll)) d.Set("request_rules", []string(*r.Basic.RequestRules)) d.Set("response_rules", []string(*r.Basic.ResponseRules)) d.Set("ssl_add_http_headers", bool(*r.SSL.AddHTTPHeaders)) d.Set("ssl_decrypt", bool(*r.Basic.SSLDecrypt)) d.Set("ssl_server_cert_default", string(*r.SSL.ServerCertDefault)) d.Set("ssl_server_cert_host_mapping", flattenServerCertHostMappingTable(*r.SSL.ServerCertHostMapping)) d.Set("syslog_format", string(*r.Syslog.Format)) d.Set("web_cache_enabled", bool(*r.WebCache.Enabled)) d.Set("web_cache_max_time", int(*r.WebCache.MaxTime)) return nil }
func resourceRateSet(d *schema.ResourceData, meta interface{}) error { c := meta.(*providerConfig).client r := stingray.NewRate(d.Get("name").(string)) setInt(&r.Basic.MaxRatePerMinute, d, "max_rate_per_minute") setInt(&r.Basic.MaxRatePerSecond, d, "max_rate_per_second") setString(&r.Basic.Note, d, "note") _, err := c.Set(r) if err != nil { return err } d.SetId(d.Get("name").(string)) return nil }
func resourceMonitorRead(d *schema.ResourceData, meta interface{}) error { c := meta.(*providerConfig).client r, resp, err := c.GetMonitor(d.Get("name").(string)) if err != nil { if resp != nil && resp.StatusCode == 404 { // The resource doesn't exist anymore d.SetId("") return nil } return fmt.Errorf("Error reading resource: %s", err) } d.Set("back_off", bool(*r.Basic.BackOff)) d.Set("delay", int(*r.Basic.Delay)) d.Set("failures", int(*r.Basic.Failures)) d.Set("http_authentication", string(*r.HTTP.Authentication)) d.Set("http_body_regex", string(*r.HTTP.BodyRegex)) d.Set("http_host_header", string(*r.HTTP.HostHeader)) d.Set("http_path", string(*r.HTTP.Path)) d.Set("http_status_regex", string(*r.HTTP.StatusRegex)) d.Set("machine", string(*r.Basic.Machine)) d.Set("note", string(*r.Basic.Note)) d.Set("rtsp_body_regex", string(*r.RTSP.BodyRegex)) d.Set("rtsp_path", string(*r.RTSP.Path)) d.Set("rtsp_status_regex", string(*r.RTSP.StatusRegex)) d.Set("scope", string(*r.Basic.Scope)) d.Set("script_arguments", flattenScriptArgumentsTable(*r.Script.Arguments)) d.Set("script_program", string(*r.Script.Program)) d.Set("sip_body_regex", string(*r.SIP.BodyRegex)) d.Set("sip_status_regex", string(*r.SIP.StatusRegex)) d.Set("sip_transport", string(*r.SIP.Transport)) d.Set("tcp_close_string", string(*r.TCP.CloseString)) d.Set("tcp_max_response_len", int(*r.TCP.MaxResponseLen)) d.Set("tcp_response_regex", string(*r.TCP.ResponseRegex)) d.Set("tcp_write_string", string(*r.TCP.WriteString)) d.Set("timeout", int(*r.Basic.Timeout)) d.Set("type", string(*r.Basic.Type)) d.Set("udp_accept_all", bool(*r.UDP.AcceptAll)) d.Set("use_ssl", bool(*r.Basic.UseSSL)) d.Set("verbose", bool(*r.Basic.Verbose)) return nil }
func resourceSSLServerKeySet(d *schema.ResourceData, meta interface{}) error { c := meta.(*providerConfig).client r := stingray.NewSSLServerKey(d.Get("name").(string)) setString(&r.Basic.Note, d, "note") setString(&r.Basic.Private, d, "private") setString(&r.Basic.Public, d, "public") setString(&r.Basic.Request, d, "request") _, err := c.Set(r) if err != nil { return err } d.SetId(d.Get("name").(string)) return nil }
func resourceServiceLevelMonitorSet(d *schema.ResourceData, meta interface{}) error { c := meta.(*providerConfig).client r := stingray.NewServiceLevelMonitor(d.Get("name").(string)) setString(&r.Basic.Note, d, "note") setInt(&r.Basic.ResponseTime, d, "response_time") setInt(&r.Basic.SeriousThreshold, d, "serious_threshold") setInt(&r.Basic.WarningThreshold, d, "warning_threshold") _, err := c.Set(r) if err != nil { return err } d.SetId(d.Get("name").(string)) return nil }
func resourceMonitorScriptRead(d *schema.ResourceData, meta interface{}) error { c := meta.(*providerConfig).client r, resp, err := c.GetMonitorScript(d.Get("name").(string)) if err != nil { if resp != nil && resp.StatusCode == 404 { // The resource doesn't exist anymore d.SetId("") return nil } return fmt.Errorf("Error reading resource: %s", err) } d.Set("content", hashString(string(r.Content))) return nil }
func resourcePoolRead(d *schema.ResourceData, meta interface{}) error { c := meta.(*providerConfig).client r, resp, err := c.GetPool(d.Get("name").(string)) if err != nil { if resp != nil && resp.StatusCode == 404 { // The resource doesn't exist anymore d.SetId("") return nil } return fmt.Errorf("Error reading resource: %s", err) } d.Set("bandwidth_class", string(*r.Basic.BandwidthClass)) d.Set("connection_max_connect_time", int(*r.Connection.MaxConnectTime)) d.Set("connection_max_connections_per_node", int(*r.Connection.MaxConnectionsPerNode)) d.Set("connection_max_queue_size", int(*r.Connection.MaxQueueSize)) d.Set("connection_max_reply_time", int(*r.Connection.MaxReplyTime)) d.Set("connection_queue_timeout", int(*r.Connection.QueueTimeout)) d.Set("failure_pool", string(*r.Basic.FailurePool)) d.Set("load_balancing_algorithm", string(*r.LoadBalancing.Algorithm)) d.Set("load_balancing_priority_enabled", bool(*r.LoadBalancing.PriorityEnabled)) d.Set("load_balancing_priority_nodes", int(*r.LoadBalancing.PriorityNodes)) d.Set("max_connection_attempts", int(*r.Basic.MaxConnectionAttempts)) d.Set("max_idle_connections_pernode", int(*r.Basic.MaxIdleConnectionsPerNode)) d.Set("max_timed_out_connection_attempts", int(*r.Basic.MaxTimedOutConnectionAttempts)) d.Set("monitors", []string(*r.Basic.Monitors)) d.Set("node_close_with_rst", bool(*r.Basic.NodeCloseWithRST)) d.Set("node_connection_attempts", int(*r.Basic.NodeConnectionAttempts)) d.Set("nodes", nodesTableToNodes(*r.Basic.NodesTable)) d.Set("note", string(*r.Basic.Note)) d.Set("passive_monitoring", bool(*r.Basic.PassiveMonitoring)) d.Set("persistence_class", string(*r.Basic.PersistenceClass)) d.Set("tcp_nagle", bool(*r.TCP.Nagle)) d.Set("udp_accept_from", string(*r.UDP.AcceptFrom)) d.Set("udp_accept_from_mask_class", string(*r.UDP.AcceptFromMask)) d.Set("transparent", bool(*r.Basic.Transparent)) return nil }
func resourceMonitorSet(d *schema.ResourceData, meta interface{}) error { c := meta.(*providerConfig).client r := stingray.NewMonitor(d.Get("name").(string)) setBool(&r.Basic.BackOff, d, "back_off") setInt(&r.Basic.Delay, d, "delay") setInt(&r.Basic.Failures, d, "failures") setString(&r.HTTP.Authentication, d, "http_authentication") setString(&r.HTTP.BodyRegex, d, "http_body_regex") setString(&r.HTTP.HostHeader, d, "http_host_header") setString(&r.HTTP.Path, d, "http_path") setString(&r.HTTP.StatusRegex, d, "http_status_regex") setString(&r.Basic.Machine, d, "machine") setString(&r.Basic.Note, d, "note") setString(&r.RTSP.BodyRegex, d, "rtsp_body_regex") setString(&r.RTSP.Path, d, "rtsp_path") setString(&r.RTSP.StatusRegex, d, "rtsp_status_regex") setString(&r.Basic.Scope, d, "scope") setScriptArgumentsTable(&r.Script.Arguments, d, "script_arguments") setString(&r.Script.Program, d, "script_program") setString(&r.SIP.BodyRegex, d, "sip_body_regex") setString(&r.SIP.StatusRegex, d, "sip_status_regex") setString(&r.SIP.Transport, d, "sip_transports") setString(&r.TCP.CloseString, d, "tcp_close_string") setInt(&r.TCP.MaxResponseLen, d, "tcp_max_response_len") setString(&r.TCP.ResponseRegex, d, "tcp_response_regex") setString(&r.TCP.WriteString, d, "tcp_write_string") setInt(&r.Basic.Timeout, d, "timeout") setString(&r.Basic.Type, d, "type") setBool(&r.UDP.AcceptAll, d, "udp_accept_all") setBool(&r.Basic.UseSSL, d, "use_ssl") setBool(&r.Basic.Verbose, d, "verbose") _, err := c.Set(r) if err != nil { return err } d.SetId(d.Get("name").(string)) return nil }
func resourceRateRead(d *schema.ResourceData, meta interface{}) error { c := meta.(*providerConfig).client r, resp, err := c.GetRate(d.Get("name").(string)) if err != nil { if resp != nil && resp.StatusCode == 404 { // The resource doesn't exist anymore d.SetId("") return nil } return fmt.Errorf("Error reading resource: %s", err) } d.Set("max_rate_per_minute", int(*r.Basic.MaxRatePerMinute)) d.Set("max_rate_per_second", int(*r.Basic.MaxRatePerSecond)) d.Set("note", string(*r.Basic.Note)) return nil }
func resourceSSLServerKeyRead(d *schema.ResourceData, meta interface{}) error { c := meta.(*providerConfig).client r, resp, err := c.GetSSLServerKey(d.Get("name").(string)) if err != nil { if resp != nil && resp.StatusCode == 404 { // The resource doesn't exist anymore d.SetId("") return nil } return fmt.Errorf("Error reading resource: %s", err) } d.Set("note", string(*r.Basic.Note)) d.Set("private", string(*r.Basic.Private)) d.Set("public", string(*r.Basic.Public)) d.Set("request", string(*r.Basic.Request)) return nil }
func resourceServiceLevelMonitorRead(d *schema.ResourceData, meta interface{}) error { c := meta.(*providerConfig).client r, resp, err := c.GetServiceLevelMonitor(d.Get("name").(string)) if err != nil { if resp != nil && resp.StatusCode == 404 { // The resource doesn't exist anymore d.SetId("") return nil } return fmt.Errorf("Error reading resource: %s", err) } d.Set("note", string(*r.Basic.Note)) d.Set("response_time", int(*r.Basic.ResponseTime)) d.Set("serious_threshold", int(*r.Basic.SeriousThreshold)) d.Set("warning_threshold", int(*r.Basic.WarningThreshold)) return nil }
func resourceTrafficIPGroupSet(d *schema.ResourceData, meta interface{}) error { c := meta.(*providerConfig).client r := stingray.NewTrafficIPGroup(d.Get("name").(string)) setBool(&r.Basic.Enabled, d, "enabled") setBool(&r.Basic.HashSourcePort, d, "hash_source_port") setStringSet(&r.Basic.IPAddresses, d, "ipaddresses") setBool(&r.Basic.KeepTogether, d, "keeptogether") setInt(&r.Basic.Location, d, "location") setStringSet(&r.Basic.Machines, d, "machines") setString(&r.Basic.Mode, d, "mode") setString(&r.Basic.Multicast, d, "multicast") setString(&r.Basic.Note, d, "note") setInt(&r.Basic.RHIOSPFV2MetricBase, d, "rhi_ospfv2_metric_base") setInt(&r.Basic.RHIOSPFV2PassiveMetricOffset, d, "rhi_ospfv2_passive_metric_offset") setStringSet(&r.Basic.Slaves, d, "slaves") ns := meta.(*providerConfig).validNetworks if len(ns) > 0 && *r.Basic.IPAddresses != nil { for _, s := range *r.Basic.IPAddresses { ip := net.ParseIP(s) if ip == nil { return fmt.Errorf("Invalid IP address: %s", s) } if !ns.Contains(ip) { return fmt.Errorf("IP address %s is not in the valid networks", ip) } } } _, err := c.Set(r) if err != nil { return err } d.SetId(d.Get("name").(string)) return nil }
func resourcePoolSet(d *schema.ResourceData, meta interface{}) error { c := meta.(*providerConfig).client r := stingray.NewPool(d.Get("name").(string)) setString(&r.Basic.BandwidthClass, d, "bandwidth_class") setInt(&r.Connection.MaxConnectTime, d, "connection_max_connect_time") setInt(&r.Connection.MaxConnectionsPerNode, d, "connection_max_connections_per_node") setInt(&r.Connection.MaxQueueSize, d, "connection_max_queue_size") setInt(&r.Connection.MaxReplyTime, d, "connection_max_reply_time") setInt(&r.Connection.QueueTimeout, d, "connection_queue_timeout") setString(&r.Basic.FailurePool, d, "failure_pool") setString(&r.LoadBalancing.Algorithm, d, "load_balancing_algorithm") setBool(&r.LoadBalancing.PriorityEnabled, d, "load_balancing_priority_enabled") setInt(&r.LoadBalancing.PriorityNodes, d, "load_balancing_priority_nodes") setInt(&r.Basic.MaxConnectionAttempts, d, "max_connection_attempts") setInt(&r.Basic.MaxIdleConnectionsPerNode, d, "max_idle_connections_pernode") setInt(&r.Basic.MaxTimedOutConnectionAttempts, d, "max_timed_out_connection_attempts") setStringSet(&r.Basic.Monitors, d, "monitors") setBool(&r.Basic.NodeCloseWithRST, d, "node_close_with_rst") setInt(&r.Basic.NodeConnectionAttempts, d, "node_connection_attempts") setNodesTable(&r.Basic.NodesTable, d, "nodes") setString(&r.Basic.Note, d, "note") setBool(&r.Basic.PassiveMonitoring, d, "passive_monitoring") setString(&r.Basic.PersistenceClass, d, "persistence_class") setBool(&r.TCP.Nagle, d, "tcp_nagle") setBool(&r.Basic.Transparent, d, "transparent") setString(&r.UDP.AcceptFrom, d, "udp_accept_from") setString(&r.UDP.AcceptFromMask, d, "udp_accept_from_mask") _, err := c.Set(r) if err != nil { return err } d.SetId(d.Get("name").(string)) return nil }