def __init__(self, xml): ResourceDefinition.__init__(self, xml) self.healthcheck_name = self.get_option_value(xml, 'name', str) self.description = self.get_option_value(xml, 'description', str, optional=True) self.host = self.get_option_value(xml, 'host', str, optional=True) self.path = self.get_option_value(xml, 'path', str, empty=False) self.port = self.get_option_value(xml, 'port', int, positive=True) self.check_interval = self.get_option_value(xml, 'checkInterval', int, positive=True) self.timeout = self.get_option_value(xml, 'timeout', int, positive=True) self.unhealthy_threshold = self.get_option_value(xml, 'unhealthyThreshold', int, positive=True) self.healthy_threshold = self.get_option_value(xml, 'healthyThreshold', int, positive=True)
def __init__(self, xml): ResourceDefinition.__init__(self, xml) self.addr_name = self.get_option_value(xml, 'name', str) self.copy_option(xml, 'region', str) self.copy_option(xml,'ipAddress',str, optional = True)
def __init__(self, xml): ResourceDefinition.__init__(self, xml) self.targetpool_name = self.get_option_value(xml, "name", str) self.copy_option(xml, "region", str) self.copy_option(xml, "healthCheck", "resource", optional=True) def machine_to_url(xml): spec = xml.find("attr[@name='gce']") if spec is None: return None return "https://www.googleapis.com/compute/v1/projects/{0}/zones/{1}/instances/{2}".format( self.project, spec.find("attrs/attr[@name='region']/string").get("value"), spec.find("attrs/attr[@name='machineName']/string").get("value"), ) mlist = xml.find("attrs/attr[@name='machines']/list") self.machines = list( set([machine_to_url(e) for e in mlist.findall("attrs")] + [e.get("value") for e in mlist.findall("string")]) ) if not all(m for m in self.machines): raise Exception( "target pool machine specification must be either a NixOps " "machine resource or a fully-qualified GCE resource URL" )
def __init__(self, xml): ResourceDefinition.__init__(self, xml) self.disk_name = self.get_option_value(xml, 'name', str) self.copy_option(xml, 'region', str) self.copy_option(xml, 'size', int, optional = True) self.copy_option(xml, 'snapshot', str, optional = True) self.copy_option(xml, 'image', 'resource', optional = True)
def __init__(self, xml): ResourceDefinition.__init__(self, xml) self.disk_name = self.get_option_value(xml, 'name', str) self.copy_option(xml, 'region', str) self.copy_option(xml, 'size', int, optional=True) self.copy_option(xml, 'snapshot', str, optional=True) self.copy_option(xml, 'image', 'resource', optional=True)
def __init__(self, xml): ResourceDefinition.__init__(self, xml) self.bucket_name = self.get_option_value(xml, "name", str) self.cors = sorted( [ { "max_age_seconds": self.get_option_value(x, "maxAgeSeconds", int, optional=True), "methods": self.get_option_value(x, "methods", "strlist"), "origins": self.get_option_value(x, "origins", "strlist"), "response_headers": self.get_option_value(x, "responseHeaders", "strlist"), } for x in xml.find("attrs/attr[@name='cors']/list") ] ) def parse_lifecycle(x): cond_x = x.find("attr[@name='conditions']") created_before = self.get_option_value(cond_x, "createdBefore", str, optional=True) if created_before: m = re.match(r"^(\d*)-(\d*)-(\d*)$", created_before) if m: normalized_created_before = "{0[0]:0>4}-{0[1]:0>2}-{0[2]:0>2}".format(m.groups()) else: raise Exception("createdBefore must be a date in 'YYYY-MM-DD' format") else: normalized_created_before = None return { "action": self.get_option_value(x, "action", str), "age": self.get_option_value(cond_x, "age", int, optional=True), "is_live": self.get_option_value(cond_x, "isLive", bool, optional=True), "created_before": normalized_created_before, "number_of_newer_versions": self.get_option_value(cond_x, "numberOfNewerVersions", int, optional=True), } self.lifecycle = sorted([parse_lifecycle(x) for x in xml.find("attrs/attr[@name='lifecycle']/list")]) if any(all(v is None for k, v in r.iteritems() if k != "action") for r in self.lifecycle): raise Exception( "Bucket '{0}' object lifecycle management " "rule must specify at least one condition".format(self.bucket_name) ) logx = xml.find("attrs/attr[@name='logging']") self.copy_option(logx, "logBucket", "resource", optional=True) self.copy_option(logx, "logObjectPrefix", str, optional=True) self.region = self.get_option_value(xml, "location", str) self.copy_option(xml, "storageClass", str) self.versioning_enabled = self.get_option_value(xml.find("attrs/attr[@name='versioning']"), "enabled", bool) webx = xml.find("attrs/attr[@name='website']") self.website_main_page_suffix = self.get_option_value(webx, "mainPageSuffix", str, optional=True) self.website_not_found_page = self.get_option_value(webx, "notFoundPage", str, optional=True)
def __init__(self, xml): ResourceDefinition.__init__(self, xml) self.route_name = self.get_option_value(xml, 'name', str) self.description = self.get_option_value(xml, 'description', str, optional=True) self.network = self.get_option_value(xml, 'network', str) self.priority = self.get_option_value(xml, 'priority', int) self.nextHop = self.get_option_value(xml, 'nextHop', str, optional=True) self.destination = self.get_option_value(xml, 'destination', str) self.tags = self.get_option_value(xml, 'tags', "strlist", optional=True)
def __init__(self, xml): ResourceDefinition.__init__(self, xml) self.bucket_name = self.get_option_value(xml, 'name', str) self.cors = sorted( [ { 'max_age_seconds': self.get_option_value(x, 'maxAgeSeconds', int, optional = True), 'methods': self.get_option_value(x, 'methods', 'strlist'), 'origins': self.get_option_value(x, 'origins', 'strlist'), 'response_headers': self.get_option_value(x, 'responseHeaders', 'strlist') } for x in xml.find("attrs/attr[@name='cors']/list") ] ) def parse_lifecycle(x): cond_x = x.find("attr[@name='conditions']") created_before = self.get_option_value(cond_x, 'createdBefore', str, optional = True) if created_before: m = re.match(r"^(\d*)-(\d*)-(\d*)$", created_before) if m: normalized_created_before = "{0[0]:0>4}-{0[1]:0>2}-{0[2]:0>2}".format(m.groups()) else: raise Exception("createdBefore must be a date in 'YYYY-MM-DD' format") else: normalized_created_before = None return { 'action': self.get_option_value(x, 'action', str), 'age': self.get_option_value(cond_x, 'age', int, optional = True), 'is_live': self.get_option_value(cond_x, 'isLive', bool, optional = True), 'created_before': normalized_created_before, 'number_of_newer_versions': self.get_option_value(cond_x, 'numberOfNewerVersions', int, optional = True) } self.lifecycle = sorted([ parse_lifecycle(x) for x in xml.find("attrs/attr[@name='lifecycle']/list") ]) if any( all(v is None for k,v in r.iteritems() if k != 'action') for r in self.lifecycle): raise Exception("Bucket '{0}' object lifecycle management " "rule must specify at least one condition" .format(self.bucket_name)) logx = xml.find("attrs/attr[@name='logging']") self.copy_option(logx, 'logBucket', 'resource', optional = True) self.copy_option(logx, 'logObjectPrefix', str, optional = True) self.region = self.get_option_value(xml, 'location', str) self.copy_option(xml, 'storageClass', str) self.versioning_enabled = self.get_option_value( xml.find("attrs/attr[@name='versioning']"), 'enabled', bool) webx = xml.find("attrs/attr[@name='website']") self.website_main_page_suffix = self.get_option_value(webx, 'mainPageSuffix', str, optional = True) self.website_not_found_page = self.get_option_value(webx, 'notFoundPage', str, optional = True)
def __init__(self, xml): ResourceDefinition.__init__(self, xml) self.healthcheck_name = self.get_option_value(xml, 'name', str) self.description = self.get_option_value(xml, 'description', str, optional = True) self.host = self.get_option_value(xml, 'host', str, optional = True) self.path = self.get_option_value(xml, 'path', str, empty = False) self.port = self.get_option_value(xml, 'port', int, positive = True) self.check_interval = self.get_option_value(xml, 'checkInterval', int, positive = True) self.timeout = self.get_option_value(xml, 'timeout', int, positive = True) self.unhealthy_threshold = self.get_option_value(xml, 'unhealthyThreshold', int, positive = True) self.healthy_threshold = self.get_option_value(xml, 'healthyThreshold', int, positive = True)
def __init__(self, xml): ResourceDefinition.__init__(self, xml) self.forwarding_rule_name = self.get_option_value(xml, 'name', str) self.copy_option(xml, 'region', str) self.copy_option(xml, 'protocol', str) pr = self.get_option_value(xml, 'portRange', str, optional = True) self.port_range = None if pr is None else "{0}-{1}".format(pr, pr) if pr.isdigit() else pr self.copy_option(xml, 'description', str, optional = True) self.copy_option(xml, 'targetPool', 'resource') self.copy_option(xml, 'ipAddress', 'resource', optional = True)
def __init__(self, xml): ResourceDefinition.__init__(self, xml) self.network_name = self.get_option_value(xml, 'name', str) self.copy_option(xml, 'addressRange', str, empty=False) def parse_allowed(x): if x.find("list") is not None: return ([v.get("value") for v in x.findall("list/string")] + [str(v.get("value")) for v in x.findall("list/int")]) else: return None def parse_sourceranges(x): value = self.get_option_value(x, 'sourceRanges', 'strlist', optional=True) return (["0.0.0.0/0"] if value is None else value) def parse_fw(x): result = { "sourceRanges": parse_sourceranges(x), "sourceTags": self.get_option_value(x, 'sourceTags', 'strlist'), "targetTags": self.get_option_value(x, 'targetTags', 'strlist'), "allowed": { a.get("name"): parse_allowed(a) for a in x.findall( "attrs/attr[@name='allowed']/attrs/attr") } } if len(result['allowed']) == 0: raise Exception( "Firewall rule '{0}' in network '{1}' " "must provide at least one protocol/port specification". format(x.get("name"), self.network_name)) if len(result['sourceRanges']) == 0 and len( result['sourceTags']) == 0: raise Exception( "Firewall rule '{0}' in network '{1}' " "must specify at least one source range or tag".format( x.get("name"), self.network_name)) return result self.firewall = { fw.get("name"): parse_fw(fw) for fw in xml.findall("attrs/attr[@name='firewall']/attrs/attr") }
def __init__(self, xml): ResourceDefinition.__init__(self, xml) self.targetpool_name = self.get_option_value(xml, 'name', str) self.copy_option(xml, 'region', str) self.copy_option(xml, 'healthCheck', 'resource', optional = True) def machine_to_url(xml): spec = xml.find("attr[@name='gce']") if spec is None: return None return( "https://www.googleapis.com/compute/v1/projects/{0}/zones/{1}/instances/{2}" .format(self.project, spec.find("attrs/attr[@name='region']/string").get("value"), spec.find("attrs/attr[@name='machineName']/string").get("value")) ) mlist = xml.find("attrs/attr[@name='machines']/list") self.machines = list(set( [ machine_to_url(e) for e in mlist.findall("attrs") ] + [ e.get("value") for e in mlist.findall("string") ] )) if not all(m for m in self.machines): raise Exception("target pool machine specification must be either a NixOps " "machine resource or a fully-qualified GCE resource URL")
def __init__(self, xml): ResourceDefinition.__init__(self, xml) self.network_name = self.get_option_value(xml, 'name', str) self.copy_option(xml, 'addressRange', str, empty = False) def parse_allowed(x): if x.find("list") is not None: return( [v.get("value") for v in x.findall("list/string")] + [str(v.get("value")) for v in x.findall("list/int")] ) else: return None def parse_sourceranges(x): value = self.get_option_value(x, 'sourceRanges', 'strlist', optional = True) return ([ "0.0.0.0/0" ] if value is None else value) def parse_fw(x): result = { "sourceRanges": parse_sourceranges(x), "sourceTags": self.get_option_value(x, 'sourceTags', 'strlist'), "targetTags": self.get_option_value(x, 'targetTags', 'strlist'), "allowed": { a.get("name"): parse_allowed(a) for a in x.findall("attrs/attr[@name='allowed']/attrs/attr") } } if len(result['allowed']) == 0: raise Exception("Firewall rule '{0}' in network '{1}' " "must provide at least one protocol/port specification" .format(x.get("name"), self.network_name) ) if len(result['sourceRanges']) == 0 and len(result['sourceTags']) == 0: raise Exception("Firewall rule '{0}' in network '{1}' " "must specify at least one source range or tag" .format(x.get("name"), self.network_name) ) return result self.firewall = { fw.get("name"): parse_fw(fw) for fw in xml.findall("attrs/attr[@name='firewall']/attrs/attr") }
def __init__(self, xml): ResourceDefinition.__init__(self, xml) self.image_name = self.get_option_value(xml, 'name', str) self.copy_option(xml, 'sourceUri', str) self.copy_option(xml, 'description', str, optional = True)
def __init__(self, xml): ResourceDefinition.__init__(self, xml) self.image_name = self.get_option_value(xml, "name", str) self.copy_option(xml, "sourceUri", str) self.copy_option(xml, "description", str, optional=True)