def xml_for_subscription_event(subscription_id, event_type, resource_provider_namespace="cloudkeys", etag=None):
	if not etag:
		etag = utility.generate_etag()

	headers = [('Content-Type', 'application/xml')]
	x = XMLBuilder('EntityEvent', xmlns='http://schemas.microsoft.com/windowsazure')
	x.EventId(subscription_id)
	x.ListenerId(resource_provider_namespace)
	x.EntityType("Subscription")
	x.EntityState(event_type)
	with x.EntityId:
		x.Id(subscription_id)
		x.Created(str(datetime.now()))
	x.IsAsync("false")
	x.OperationId(etag)
	with x.Properties:
		with x.EntityProperty:
			x.PropertyName("ResourceType")
			x.PropertyValue("cloudkeys")
		with x.EntityProperty:
			x.PropertyName("EMail")
			x.PropertyValue("*****@*****.**")		
		with x.EntityProperty:
			x.PropertyName("OptIn")
			x.PropertyValue("False")		

	return str(x)
	def upgrade(self):		
		etag = generate_etag()
		Printer.start_test("Update plan")

		# CHECK: Plan upgrade succeeds
		(status, response) = self.client.perform_request(
				"subscriptions/%s/cloudservices/%s/resources/%s/%s" % (
					self.config["subscription_id"],
					self.config["cloud_service_name"],
					self.config["resource_type"],
					self.config["resource_name"]),
				'PUT',
				xmlutil.xml_for_create_resource(
					plan=self.config['upgrade_plan'],
					resource_type=self.config['resource_type'],
					promotion_code=self.config['promo_code'],
					etag=etag
				),
				validate_xml=True
			)

		if status in [200, 201]:
			Printer.success("Upgrade Resource succeeded.")
			Printer.info("Checking XML")
		else:
			Printer.error("Upgrade Resource failed with HTTP status code %s" % status)
			return

		t = xmlutil.get_subtree_from_xml_string(response)
		self._validate_resource_response(etag, t)
		Printer.info("Checking if new plan is %s" % self.config['upgrade_plan'])
		self._check_node_value(t, './{0}Plan', self.config['upgrade_plan'])
示例#3
0
    def upgrade(self):
        etag = generate_etag()
        Printer.start_test("Update plan")

        # CHECK: Plan upgrade succeeds
        (status, response) = self.client.perform_request(
            "subscriptions/%s/cloudservices/%s/resources/%s/%s" %
            (self.config["subscription_id"], self.config["cloud_service_name"],
             self.config["resource_type"], self.config["resource_name"]),
            'PUT',
            xmlutil.xml_for_create_resource(
                plan=self.config['upgrade_plan'],
                resource_type=self.config['resource_type'],
                promotion_code=self.config['promo_code'],
                etag=etag),
            validate_xml=True)

        if status in [200, 201]:
            Printer.success("Upgrade Resource succeeded.")
            Printer.info("Checking XML")
        else:
            Printer.error("Upgrade Resource failed with HTTP status code %s" %
                          status)
            return

        t = xmlutil.get_subtree_from_xml_string(response)
        self._validate_resource_response(etag, t)
        Printer.info("Checking if new plan is %s" %
                     self.config['upgrade_plan'])
        self._check_node_value(t, './{0}Plan', self.config['upgrade_plan'])
示例#4
0
def xml_for_subscription_event(subscription_id,
                               event_type,
                               resource_provider_namespace="cloudkeys",
                               etag=None):
    if not etag:
        etag = utility.generate_etag()

    headers = [('Content-Type', 'application/xml')]
    x = XMLBuilder('EntityEvent',
                   xmlns='http://schemas.microsoft.com/windowsazure')
    x.EventId(subscription_id)
    x.ListenerId(resource_provider_namespace)
    x.EntityType("Subscription")
    x.EntityState(event_type)
    with x.EntityId:
        x.Id(subscription_id)
        x.Created(str(datetime.now()))
    x.IsAsync("false")
    x.OperationId(etag)
    with x.Properties:
        with x.EntityProperty:
            x.PropertyName("ResourceType")
            x.PropertyValue("cloudkeys")
        with x.EntityProperty:
            x.PropertyName("EMail")
            x.PropertyValue("*****@*****.**")
        with x.EntityProperty:
            x.PropertyName("OptIn")
            x.PropertyValue("False")

    return str(x)
示例#5
0
    def delete(self):
        etag = generate_etag()
        Printer.start_test("Delete Resource")

        (status, response) = self.client.perform_request(
            "subscriptions/%s/cloudservices/%s/resources/%s/%s" %
            (self.config["subscription_id"], self.config["cloud_service_name"],
             self.config["resource_type"], self.config["resource_name"]),
            'DELETE', None)

        if status in [200, 201]:
            Printer.success("Delete Resource succeeded.")
        else:
            Printer.error("Delete Resource failed with HTTP status code %s" %
                          status)
            return
    def create(self):
        etag = generate_etag()
        Printer.start_test("Create resource")
        (status, response) = self.client.perform_request(
            "subscriptions/%s/Events" % self.config["subscription_id"],
            "POST",
            xmlutil.xml_for_subscription_event(
                self.config["subscription_id"],
                self.config["resource_provider_namespace"],
                self.config["resource_type"],
                "Registered",
            ),
        )

        # CHECK: Subscription Register event succeeds
        if status in [200, 201]:
            Printer.success("Subscription register event succeeded")
        else:
            Printer.error("Subscription register event failed with HTTP status code %s" % status)
            return

            # CHECK: Resource creation succeeds
        (status, response) = self.client.perform_request(
            "subscriptions/%s/cloudservices/%s/resources/%s/%s"
            % (
                self.config["subscription_id"],
                self.config["cloud_service_name"],
                self.config["resource_type"],
                self.config["resource_name"],
            ),
            "PUT",
            xmlutil.xml_for_create_resource(
                plan=self.config["purchase_plan"],
                resource_type=self.config["resource_type"],
                promotion_code=self.config["promo_code"],
                etag=etag,
            ),
        )

        if status in [200, 201]:
            Printer.success("Resource creation succeeded")
            Printer.info("Checking XML")
        else:
            Printer.error("Resource creation event failed with HTTP status code %s" % status)

        t = xmlutil.get_subtree_from_xml_string(response)
        self._validate_resource_response(etag, t)
	def delete(self):
		etag = generate_etag()
		Printer.start_test("Delete Resource")

		(status, response) = self.client.perform_request(
				"subscriptions/%s/cloudservices/%s/resources/%s/%s" % (
					self.config["subscription_id"],
					self.config["cloud_service_name"],
					self.config["resource_type"],
					self.config["resource_name"]),
				'DELETE',
				None
			)

		if status in [200, 201]:
			Printer.success("Delete Resource succeeded.")
		else:
			Printer.error("Delete Resource failed with HTTP status code %s" % status)
			return
示例#8
0
    def create(self):
        etag = generate_etag()
        Printer.start_test("Create resource")
        (status, response) = self.client.perform_request(
            "subscriptions/%s/Events" % self.config['subscription_id'], 'POST',
            xmlutil.xml_for_subscription_event(
                self.config["subscription_id"],
                self.config["resource_provider_namespace"],
                self.config["resource_type"], "Registered"))

        # CHECK: Subscription Register event succeeds
        if status in [200, 201]:
            Printer.success("Subscription register event succeeded")
        else:
            Printer.error(
                "Subscription register event failed with HTTP status code %s" %
                status)
            return

        # CHECK: Resource creation succeeds
        (status, response) = self.client.perform_request(
            "subscriptions/%s/cloudservices/%s/resources/%s/%s" %
            (self.config["subscription_id"], self.config["cloud_service_name"],
             self.config["resource_type"], self.config["resource_name"]),
            'PUT',
            xmlutil.xml_for_create_resource(
                plan=self.config['purchase_plan'],
                resource_type=self.config['resource_type'],
                promotion_code=self.config['promo_code'],
                etag=etag))

        if status in [200, 201]:
            Printer.success("Resource creation succeeded")
            Printer.info("Checking XML")
        else:
            Printer.error(
                "Resource creation event failed with HTTP status code %s" %
                status)

        t = xmlutil.get_subtree_from_xml_string(response)
        self._validate_resource_response(etag, t)