Exemplo n.º 1
0
def create_sddc(org_id, region, sddc_name, sddc_type, vpc_cidr, provider,
                customer_subnet_id, connected_account_id, num_hosts, link_aws,
                vmc_client):
    sddc_config = AwsSddcConfig(
        region=region,
        name=sddc_name,
        sddc_type=sddc_type,
        account_link_sddc_config=[
            AccountLinkSddcConfig(customer_subnet_ids=[customer_subnet_id],
                                  connected_account_id=connected_account_id)
        ] if link_aws else None,
        vpc_cidr=vpc_cidr,
        provider=provider,
        num_hosts=num_hosts,
        account_link_config=None if link_aws else AccountLinkConfig(True),
        deployment_type=SddcConfig.DEPLOYMENT_TYPE_SINGLEAZ)

    try:
        task = vmc_client.orgs.Sddcs.create(org=org_id,
                                            sddc_config=sddc_config)
    except InvalidRequest as err:
        error_response = err.data.convert_to(ErrorResponse)
        messages = error_response.error_messages
        message = None if len(messages) <= 0 else messages[0]
        raise Exception(message)
    return task.id
Exemplo n.º 2
0
    def createSddc(self, sddcName=None, config=None, verbose=False):

        if not sddcName:
            raise ValueError('You must supply an SDDC name')

        for sddc in self.sddcs:
            if sddc.name == sddcName:
                print("SDDC {} already exists.".format(sddcName))
                return

        orgConfig = self.config.Organizations[self.org.id]
        podConfig = orgConfig.SddcPods[sddcName]

        sddcConfig = AwsSddcConfig(
            account_link_sddc_config=[
                AccountLinkSddcConfig(
                    customer_subnet_ids=[orgConfig.LinkedSubnets[0]],
                    connected_account_id=self.getConnectedAccountID(
                        orgConfig.LinkedAccount))
            ],
            name=sddcName,
            vxlan_subnet=podConfig.VxlanSubnet,
            vpc_cidr=podConfig.ManagementCidr,
            provider=self.config.WorkshopConfig.Provider,
            sso_domain=self.config.WorkshopConfig.SsoDomain,
            num_hosts=self.config.WorkshopConfig.NumHosts,
            deployment_type=self.config.WorkshopConfig.DeploymentType,
            region=self.config.WorkshopConfig.Region)

        # For single node cluster, an extra flag must be set
        if sddcConfig.num_hosts == 1:
            sddcConfig.sddc_type = "1NODE"

        # For legacy API/SDK combinations, there was a setting for vpc_name
        # that was later removed from the prototype.  The following check
        # ensures backwards compatability
        try:
            getattr(sddcConfig, 'vpc_name')
            sddcConfig.vpc_name = None
        except AttributeError:
            pass

        if verbose:
            print(sddcConfig)

        try:
            task = self.vmc.vmc_client.orgs.Sddcs.create(
                org=self.org.id, sddc_config=sddcConfig)

            if verbose:
                print(task.id)

            return task.id

        except InvalidRequest as e:
            # Convert InvalidRequest to ErrorResponse to get error message
            error_response = e.data.convert_to(ErrorResponse)
            raise Exception(error_response.error_messages)
Exemplo n.º 3
0
    def create_sddc(self):
        print('\n# Example: Create a SDDC ({}) in org {}:'.format(
            self.sddc_name, self.org_id))

        account_linking_config = None

        # Get connected accounts if any
        account_ids = self.vmc_client.orgs.account_link.ConnectedAccounts.get(
            self.org_id)

        if len(account_ids) > 0:
            account_id = account_ids[0].id

            vpc_map = self.vmc_client.orgs.account_link.CompatibleSubnets.get(
                org=self.org_id,
                linked_account_id=account_id,
                region=self.region).vpc_map

            customer_subnet_id = self.get_subnet_id(vpc_map)
            if not customer_subnet_id:
                raise ValueError('No available subnet for region {}'.format(
                    self.region))

            account_linking_config = AccountLinkSddcConfig(
                customer_subnet_ids=[customer_subnet_id],
                connected_account_id=account_id)

        sddc_config = AwsSddcConfig(
            region=self.region,
            name=self.sddc_name,
            account_link_sddc_config=[account_linking_config]
            if account_linking_config else None,
            provider=os.environ.get('VMC_PROVIDER', SddcConfig.PROVIDER_AWS),
            num_hosts=self.num_hosts,
            deployment_type=SddcConfig.DEPLOYMENT_TYPE_SINGLEAZ)

        try:
            task = self.vmc_client.orgs.Sddcs.create(org=self.org_id,
                                                     sddc_config=sddc_config)
        except InvalidRequest as e:
            # Convert InvalidRequest to ErrorResponse to get error message
            error_response = e.data.convert_to(ErrorResponse)
            raise Exception(error_response.error_messages)

        wait_for_task(task_client=self.vmc_client.orgs.Tasks,
                      org_id=self.org_id,
                      task_id=task.id,
                      interval_sec=self.interval_sec)

        print('\n# Example: SDDC created:')
        self.sddc_id = task.resource_id
        sddc = self.vmc_client.orgs.Sddcs.get(self.org_id, self.sddc_id)
        self.print_output([sddc])
Exemplo n.º 4
0
    def createSddc(self, sddcName=None, config=None, verbose=False):

        if not sddcName:
            raise ValueError('You must supply an SDDC name')

        for sddc in self.sddcs:
            if sddc.name == sddcName:
                print("SDDC {} already exists.".format(sddcName))
                return

        orgConfig = self.config.Organizations[self.org.id]
        podConfig = orgConfig.SddcPods[sddcName]

        sddcConfig = AwsSddcConfig(
            account_link_sddc_config=[
                AccountLinkSddcConfig(
                    customer_subnet_ids=[orgConfig.LinkedSubnets[0]],
                    connected_account_id=self.getConnectedAccountID(
                        orgConfig.LinkedAccount))
            ],
            name=sddcName,
            vxlan_subnet=podConfig.VxlanSubnet,
            vpc_cidr=podConfig.ManagementCidr,
            vpc_name=None,
            provider=self.config.WorkshopConfig.Provider,
            sso_domain=self.config.WorkshopConfig.SsoDomain,
            num_hosts=self.config.WorkshopConfig.NumHosts,
            deployment_type=self.config.WorkshopConfig.DeploymentType,
            region=self.config.WorkshopConfig.Region)

        if verbose:
            print(sddcConfig)

        try:
            task = self.vmc.vmc_client.orgs.Sddcs.create(
                org=self.org.id, sddc_config=sddcConfig)

            if verbose:
                print(task.id)

            return task.id

        except InvalidRequest as e:
            # Convert InvalidRequest to ErrorResponse to get error message
            error_response = e.data.convert_to(ErrorResponse)
            raise Exception(error_response.error_messages)
Exemplo n.º 5
0
    def create_sddc(self, sddc_create_spec):
        """
        Create SDDC

        Parameters
        ----------
        sddc_create_spec : dict

        """

        sddc_config = AwsSddcConfig(
            region=sddc_create_spec['region'],
            name=sddc_create_spec['name'],
            account_link_sddc_config=[
                AccountLinkSddcConfig(
                    customer_subnet_ids=[sddc_create_spec['subnet_id']],
                    connected_account_id=sddc_create_spec['account_id'])
            ],
            provider=sddc_create_spec['provider'],
            num_hosts=int(sddc_create_spec['num_hosts']),
            deployment_type=SddcConfig.DEPLOYMENT_TYPE_SINGLEAZ)

        try:
            task = self.vmc_client.orgs.Sddcs.create(org=self.org_id,
                                                     sddc_config=sddc_config)
        except InvalidRequest as e:
            # Convert InvalidRequest to ErrorResponse to get error message
            error_response = e.data.convert_to(ErrorResponse)
            raise Exception(error_response.error_messages)

        # wait_for_task(task_client=self.vmc_client.orgs.Tasks,
        #               org_id=self.org_id,
        #               task_id=task.id,
        #               interval_sec=self.interval_sec)

        # print('\n# Example: SDDC created:')
        self.sddc_id = task.resource_id
        # sddc = self.vmc_client.orgs.Sddcs.get(self.org_id, self.sddc_id)
        # self.print_output([sddc])

        # self.sddc = sddc

        return self.sddc_id
Exemplo n.º 6
0
    def create_sddc(self, sddc_create_spec):
        """
        Create SDDC

        Parameters
        ----------
        sddc_create_spec : dict

        """

        # account_id = self.vmc_client.orgs.account_link.ConnectedAccounts.get(
        #     self.org_id)[0].id

        account_id = sddc_create_spec['account_id']

        # vpc_map = self.vmc_client.orgs.account_link.CompatibleSubnets.get(
        #     org=self.org_id,
        #     linked_account_id=account_id).vpc_map

        # customer_subnet_id = self.get_subnet_id(vpc_map)
        # if not customer_subnet_id:
        #     raise ValueError('No available subnet for region {}'.format(self.region))

        # sddc_config = AwsSddcConfig(
        #     region=self.region,
        #     name=self.sddc_name,
        #     account_link_sddc_config=[AccountLinkSddcConfig(
        #         customer_subnet_ids=[customer_subnet_id],
        #         connected_account_id=account_id)],
        #     provider=os.environ.get('VMC_PROVIDER', SddcConfig.PROVIDER_AWS),
        #     num_hosts=1,
        #     deployment_type=SddcConfig.DEPLOYMENT_TYPE_SINGLEAZ)

        sddc_config = AwsSddcConfig(
            region=sddc_create_spec['region'],
            name=sddc_create_spec['name'],
            account_link_sddc_config=[
                AccountLinkSddcConfig(
                    customer_subnet_ids=[sddc_create_spec['subnet_id']],
                    connected_account_id=account_id)
            ],
            provider=sddc_create_spec['provider'],
            num_hosts=int(sddc_create_spec['num_hosts']),
            deployment_type=SddcConfig.DEPLOYMENT_TYPE_SINGLEAZ)

        try:
            task = self.vmc_client.orgs.Sddcs.create(org=self.org_id,
                                                     sddc_config=sddc_config)
        except InvalidRequest as e:
            # Convert InvalidRequest to ErrorResponse to get error message
            error_response = e.data.convert_to(ErrorResponse)
            raise Exception(error_response.error_messages)

        wait_for_task(task_client=self.vmc_client.orgs.Tasks,
                      org_id=self.org_id,
                      task_id=task.id,
                      interval_sec=self.interval_sec)

        print('\n# Example: SDDC created:')
        self.sddc_id = task.resource_id
        sddc = self.vmc_client.orgs.Sddcs.get(self.org_id, self.sddc_id)
        self.print_output([sddc])
Exemplo n.º 7
0
                print("Available VMC Orgs:")
                display_org_list(vmc_orglist)
                print("\nSelect Org to work with")
                choice = int(input(" >> "))
                vmc_org = vmc_orglist[choice]
                print("Now working in " + vmc_org.display_name)

        elif ch == '3':  # List deployed SDDCs
            display_sddc_list(vmc_org.id)

        elif ch == '4':  # Provision new SDDC  ##########################################
            provider = os.environ.get('VMC_PROVIDER', 'AWS')
            #sddc_config = AwsSddcConfig(region='US_WEST_2', num_hosts=4, name='JD-Test', provider=provider)
            #account_link_sddc_config = AccountLinkSddcConfig(customer_subnet_ids=["subnet-d9d9de94"], connected_account_id="fbf80adb-5c95-3cae-bfb4-4f6df3ccdb5c" )
            account_link_sddc_config = AccountLinkSddcConfig(
                customer_subnet_ids=["subnet-cb1bf0ae"],
                connected_account_id="bf9ebc6c-d4bb-37b9-9673-4c523f6478f2")

            sddc_config = AwsSddcConfig(
                region='US_WEST_2',
                num_hosts=4,
                name='JD-Test',
                provider=provider,
                vpc_cidr="10.2.0.0/16",
                account_link_sddc_config=[account_link_sddc_config])

            print("AccountLinkSddcConfig :\n\n" +
                  str(account_link_sddc_config))
            print("\nAwsSddcConfig :\n\n" + str(sddc_config))
            print("\norg id: " + str(vmc_org.id))